import request from "../../common/request"
const store = {
	state: {
		userInfo: {},
	},
	getters: {
		getUserInfo: state => {
			return state.userInfo
		},
	},
	mutations: {
		setUserInfo(state, data) {
			state.userInfo = {
				...state.userInfo,
				...data
			}
		},
		removeUserInfo(state) {
			state.userInfo = {}
		},
	},
	actions: {
		async risk(state) {
			state.state.userInfo.isConfrimRisk = 1
		},
		async updateUserInfo(context) {
			const userInfo = context.state.userInfo
			console.log('updateUserInfo')
			if (userInfo.user_id) {
				const ret = await request({
					url: `/user/user/getUserByAddress?address=${userInfo.address}`,
					method: 'get'
				})
				if (ret && ret.data.code === 0) {
					context.commit("setUserInfo", { ...userInfo, ...ret.data.data })
				}
			}
		}
	}
}

export default store